package com.join.template.core.configuration;

import com.join.template.core.constant.Constant;
import com.join.template.core.util.resource.ResourceFind;
import com.join.template.core.util.resource.ResourceInfo;
import com.join.template.core.util.TemplateException;
import lombok.Data;

import java.io.IOException;

/**
 * @author CAOYOU/625954232@qq.com
 * @Title: 模版引擎总配置
 * @date 2019/8/19 11:52
 */
@Data
public class JoinConfig {
    //编码
    private String encoding;
    //项目资源目录
    private String resourcesDir;
    //模版工厂类型
    private String cacheType;
    //模版缓存大小
    private Integer cacheSize;
    //表达式配置
    private ExpressionConfig expression = new ExpressionConfig();
    //类型转配置
    private ClassConvertConfig baseType = new ClassConvertConfig();

    private ResourceFind resourceFind;

    public JoinConfig() {
        init();
    }

    /**
     * 初始化
     */
    public void init() {
        this.resourceFind = new ResourceFind();
        this.resourcesDir = "";
        this.encoding = "UTF-8";
        this.cacheType = Constant.TYPE_MAP;
        this.cacheSize = 50;
    }


    public ResourceInfo getResource(String fileName) {
        try {
            return resourceFind.getURL(this.resourcesDir + fileName);
        } catch (IOException e) {
            throw new TemplateException("没有该文件", e);
        }
    }

    public String getUserDir() {
        return resourceFind.getUserDir();
    }
}
